SlideShare a Scribd company logo
1 of 2
Download to read offline
[NOMBRE DEL AUTOR] 1
public static void main(String[] args) {
Scanner br = new Scanner (System.in);
int n, otr[], cont = 0, Max = 0;double not[];
do{
System.out.print("Ingrese tamaño del vector: ");
n = br.nextInt();
}while(n < 1);
not = new double[n];
otr = new int[n];
for(int i = 0; i < not.length; i++){
System.out.print("[" + i + "]: ");
not[i] = br.nextDouble();
}
for(int i = 0; i < not.length; i++){
cont = 0;
for(int j = 0; j < not.length; j++){
if(not[i] == not[j]){
otr[i] = ++cont;
}
}
}
for(int i = 0; i < otr.length; i++){
for(int j = 0; j < otr.length; j++){
if( otr[ i ] > otr[j] ){
Max = Math.max(Max, otr[i]);
}else{
Max = Math.max(Max, otr[j]);
}
}
}
System.out.print("nLa moda es: { ");
for(int i = 0; i < not.length; i++){
cont = 0;
for(int j = 0; j < not.length; j++){
if(not[i] == not[j]){
++cont;
if(cont == Max){
if(i == j){
System.out.print(not[i]+" ");
}
}
}
}
}
System.out.println("}");
}
1) Ingresar N notas en un arreglo y determinar la Moda.
[NOMBRE DEL AUTOR] 2
 Incluso usando el método Math.Random()
public static double round(double Número, int n){
int posP,cont=0,Tdig;
String num, num2 = "";
num = String.valueOf(Número);
Tdig = num.length() - num.indexOf(".") - 1;
if(n < 0){
n = 0;
}else if(n > Tdig){
n = Tdig;
}
char [] Carac = num.toCharArray();
for(int i = 0; i < Carac.length; i++){
if(Carac[i] == 'E'){
cont = 1;
}
}
if(cont == 0){
posP = num.indexOf(".");
if(n < (num.length() - posP - 1)){
for(int i = 0; i < (posP + n + 1); i++){
num2 += Carac[i];
}
Número = Double.parseDouble(num2);
String ver = String.valueOf(Carac[posP + n + 1]);
int ver1 = Integer.parseInt(ver);
if(ver1 > 4){
if(n == 0){
Número = Número + 1;
}else{
ver = "";
char zicklon[] = new char [2 + n];
for(int i = 0; i < zicklon.length; i++){
if(i == 0){
zicklon[0] = '0';
}else if(i == 1){
zicklon[1] = '.';
}else if(1 < i && i < (zicklon.length-1)){
zicklon[i] = '0';
}else{
zicklon[(zicklon.length-1)] = '1';
}
}
ver += String.valueOf(zicklon);
double ver2 = Double.parseDouble(ver);
Número += ver2;
String ver3 = String.valueOf(Número),Nnum="";
int length = ver3.length();
if(length > (posP + n + 1)){
char Ver [] = ver3.toCharArray();
for(int i = 0; i < (posP + n + 1); i++){
Nnum += Ver[i];
}
Número = Double.parseDouble(Nnum);
}
}
}
}
}
return Número;
}
2) Objeto para redondear un número double.

More Related Content

What's hot (19)

NSEG17 バグのはなし
NSEG17 バグのはなしNSEG17 バグのはなし
NSEG17 バグのはなし
 
Novatadas en java
Novatadas en javaNovatadas en java
Novatadas en java
 
Bodlogo
BodlogoBodlogo
Bodlogo
 
C Program : Sorting : Bubble,
C Program : Sorting : Bubble, C Program : Sorting : Bubble,
C Program : Sorting : Bubble,
 
Ejercicios.
Ejercicios. Ejercicios.
Ejercicios.
 
Heep implementation in c
Heep implementation in cHeep implementation in c
Heep implementation in c
 
vecotores programacion
vecotores programacionvecotores programacion
vecotores programacion
 
Dado un vector imprimir cuantas vocales tiene
Dado un vector imprimir cuantas vocales tieneDado un vector imprimir cuantas vocales tiene
Dado un vector imprimir cuantas vocales tiene
 
Programs
ProgramsPrograms
Programs
 
All set1
All set1All set1
All set1
 
Kelompok 2.6
Kelompok 2.6Kelompok 2.6
Kelompok 2.6
 
Ejercicio8
Ejercicio8Ejercicio8
Ejercicio8
 
Bodlogo
BodlogoBodlogo
Bodlogo
 
program sederhana
program sederhanaprogram sederhana
program sederhana
 
Practica 4 errores
Practica 4 erroresPractica 4 errores
Practica 4 errores
 
Kelompok 2.6
Kelompok 2.6Kelompok 2.6
Kelompok 2.6
 
Prueba de montecarlo
Prueba de montecarloPrueba de montecarlo
Prueba de montecarlo
 
Teknik simulasi
Teknik simulasiTeknik simulasi
Teknik simulasi
 
Programs
ProgramsPrograms
Programs
 

Viewers also liked

Viewers also liked (8)

Acc 201-final-project
Acc 201-final-projectAcc 201-final-project
Acc 201-final-project
 
Tollite hostias
Tollite hostiasTollite hostias
Tollite hostias
 
MS Program Overview 2016 (1) (1)
MS Program Overview 2016 (1) (1)MS Program Overview 2016 (1) (1)
MS Program Overview 2016 (1) (1)
 
Triptico Aprendizaje Permanente
Triptico Aprendizaje PermanenteTriptico Aprendizaje Permanente
Triptico Aprendizaje Permanente
 
Acc 201-answers
Acc 201-answersAcc 201-answers
Acc 201-answers
 
Certificado_Seguros
Certificado_SegurosCertificado_Seguros
Certificado_Seguros
 
Reporte Diario Bursátil del 19 de julio 2016
Reporte Diario Bursátil del 19 de julio 2016Reporte Diario Bursátil del 19 de julio 2016
Reporte Diario Bursátil del 19 de julio 2016
 
DocScanErinRec.
DocScanErinRec.DocScanErinRec.
DocScanErinRec.
 

Algoritmos (Moda, Redondear)

  • 1. [NOMBRE DEL AUTOR] 1 public static void main(String[] args) { Scanner br = new Scanner (System.in); int n, otr[], cont = 0, Max = 0;double not[]; do{ System.out.print("Ingrese tamaño del vector: "); n = br.nextInt(); }while(n < 1); not = new double[n]; otr = new int[n]; for(int i = 0; i < not.length; i++){ System.out.print("[" + i + "]: "); not[i] = br.nextDouble(); } for(int i = 0; i < not.length; i++){ cont = 0; for(int j = 0; j < not.length; j++){ if(not[i] == not[j]){ otr[i] = ++cont; } } } for(int i = 0; i < otr.length; i++){ for(int j = 0; j < otr.length; j++){ if( otr[ i ] > otr[j] ){ Max = Math.max(Max, otr[i]); }else{ Max = Math.max(Max, otr[j]); } } } System.out.print("nLa moda es: { "); for(int i = 0; i < not.length; i++){ cont = 0; for(int j = 0; j < not.length; j++){ if(not[i] == not[j]){ ++cont; if(cont == Max){ if(i == j){ System.out.print(not[i]+" "); } } } } } System.out.println("}"); } 1) Ingresar N notas en un arreglo y determinar la Moda.
  • 2. [NOMBRE DEL AUTOR] 2  Incluso usando el método Math.Random() public static double round(double Número, int n){ int posP,cont=0,Tdig; String num, num2 = ""; num = String.valueOf(Número); Tdig = num.length() - num.indexOf(".") - 1; if(n < 0){ n = 0; }else if(n > Tdig){ n = Tdig; } char [] Carac = num.toCharArray(); for(int i = 0; i < Carac.length; i++){ if(Carac[i] == 'E'){ cont = 1; } } if(cont == 0){ posP = num.indexOf("."); if(n < (num.length() - posP - 1)){ for(int i = 0; i < (posP + n + 1); i++){ num2 += Carac[i]; } Número = Double.parseDouble(num2); String ver = String.valueOf(Carac[posP + n + 1]); int ver1 = Integer.parseInt(ver); if(ver1 > 4){ if(n == 0){ Número = Número + 1; }else{ ver = ""; char zicklon[] = new char [2 + n]; for(int i = 0; i < zicklon.length; i++){ if(i == 0){ zicklon[0] = '0'; }else if(i == 1){ zicklon[1] = '.'; }else if(1 < i && i < (zicklon.length-1)){ zicklon[i] = '0'; }else{ zicklon[(zicklon.length-1)] = '1'; } } ver += String.valueOf(zicklon); double ver2 = Double.parseDouble(ver); Número += ver2; String ver3 = String.valueOf(Número),Nnum=""; int length = ver3.length(); if(length > (posP + n + 1)){ char Ver [] = ver3.toCharArray(); for(int i = 0; i < (posP + n + 1); i++){ Nnum += Ver[i]; } Número = Double.parseDouble(Nnum); } } } } } return Número; } 2) Objeto para redondear un número double.