【发布时间】:2017-03-26 13:21:54
【问题描述】:
我在程序中使用了变量,但我无法使用 do-while 变量制作这个程序。 (备注:我在 NetBeans 中做的,我是匈牙利人。我在程序中使用了匈牙利语文本。对不起。)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package karakterkeresés.fr;
import java.util.Scanner;
/**
*
* @author Apa---2016
*/
public class KarakterkeresésFr {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner beolv;
beolv=new Scanner(System.in);
int y=0;
String x;
System.out.print("Megadott szó:");
x=beolv.nextLine();
for(int cv=0;cv<x.length();cv++){
if(x.charAt(cv)=='a'){y++;}
else{}
}
if(y>0){System.out.println("A megadott szóban megtatlálható az 'a' karakter.");}
else{System.out.println("A megadott szóban nem megtatlálható az 'a' karakter.");}
System.out.println("A szóban "+y+" 'a' betű található.");
}
}
这是有效的。 但这不是。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package karakterkeresés.dw;
import java.util.Scanner;
/**
*
* @author Apa---2016
*/
public class KarakterkeresésDw {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner beolv;
beolv=new Scanner(System.in);
int y=0;
int z=0;
String x;
String Sg;
System.out.print("Megadott szó:");
x=beolv.nextLine();
do{
if(x.charAt(0+1)=='a'){z++;}
else{}
y++;
}
while(y<=x.length());
if(z>0){System.out.println("A megadott szóban megtalálható az 'a' betű.");}
else{System.out.println("A megadott szóban nem található meg az 'a' betű.");}
System.out.println("A megadott szóban "+z+" 'a' betű található.");
}
}
如何用do-while变量制作这个程序?
【问题讨论】:
-
你也可以省略 do 块中的 else 语句,因为它没有做任何事情......
-
请修正您的代码格式,仅此一项就可以回答/阐明您的问题。
-
请编辑您的标题和问题,因为 do-while 是一个循环,与 for 循环不同,请澄清您的问题