PDA

View Full Version : چرا جوابش عدده؟جاوا



sara.sherafati
یک شنبه 23 مهر 1391, 21:13 عصر
این برنامه ای است که سال و روز و ماه را میگیره و مشخص میکنه اون تاریخی که بش دادی چند شنبس
این دستوراتی ست که بنده به زبان جاوا در نت بینز نوشتم
ولی خطای منطقی داره و وارد دستور sweitch نمیشه

import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author sara
*/
public class yeardaymounth {
public static void main(String[] args) {
int h,q,m,k,j,y;
/*h=chan shanbas?
* q=day rooz
* m=mounth mah
* k=sal%7
* j=gharn
* y=year
*/
Scanner H=new Scanner(System.in);

System.out.println("please enter the day : ");
q=H.nextInt();

System.out.println("pleas enter the mounth : ");
m=H.nextInt();

System.out.println("pleas enter year: ");
y=H.nextInt();
k=y%7;
j=y/400;
// System.out.println("pleas enter J : ");

h=(q+(26*(m+1)/10)+k+(k/4)+(j/4)+5*j)%7;

System.out.println("h = "+h);
String name="";

switch(h){
case 1:
name="shanbe";
break;
case 2:
name="yek shanbe";
break;
case 3:
name="do shanbe";
break;
case 4:
name="se shanbe";
break;
case 5:
name="chahar shanbe";
break;
case 6:
name="panj shanbe";
break;
default:
name="jome";
}
}

}

java.source.ir
دوشنبه 24 مهر 1391, 13:10 عصر
سلام
دستور زیر را بعد از تگ switch و در انتهای کدهایت قرار بده:


System.out.println(name);


در کل باید کد شما چیزی شبیه به مورد زیر شود:


import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author sara
*/
public class yeardaymounth {
public static void main(String[] args) {
int h,q,m,k,j,y;
/*h=chan shanbas?
* q=day rooz
* m=mounth mah
* k=sal%7
* j=gharn
* y=year
*/
Scanner H=new Scanner(System.in);

System.out.println("please enter the day : ");
q=H.nextInt();

System.out.println("pleas enter the mounth : ");
m=H.nextInt();

System.out.println("pleas enter year: ");
y=H.nextInt();
k=y%7;
j=y/400;
// System.out.println("pleas enter J : ");

h=(q+(26*(m+1)/10)+k+(k/4)+(j/4)+5*j)%7;

System.out.println("h = "+h);
String name="";

switch(h){
case 1:
name="shanbe";
break;
case 2:
name="yek shanbe";
break;
case 3:
name="do shanbe";
break;
case 4:
name="se shanbe";
break;
case 5:
name="chahar shanbe";
break;
case 6:
name="panj shanbe";
break;
default:
name="jome";
}
System.out.println(name);
}

}