GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Algorithm/java/interview_1.java at master · lelea2/Algorithm

Expand file tree

/

interview_1.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
59 lines (54 loc) · 2.1 KB
/

interview_1.java

Copy path

File metadata and controls

59 lines (54 loc) · 2.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Problem: Write a function that splits a text into single words.
public static void main (String [] args) {
String[] myresult;
System.out.println(“Please enter your text: “);
Scanner in = new Scanner(System.in);
String mystr = in.nextline(); // Read String into variable
myresult = mystr.split (“ +”); // this will ignore all the space
for (int i =0; i<myresult.length; i++)
System.out.println(myresult[i]);
}
// Problem: Write a function that splits a text into single words, without using split() or StringTokenizer etc that does the same job.
public static void main (String[] args) {
System.out.println(“Please enter your text: “);
Scanner in = new Scanner(System.in);
while (in.hasNext())
{
System.out.println(in.next());
}
}
// Problem: Write a function that splits a text into single words, without using split() or StringTokenizer etc that does the same job, and without using Scanner.next().
public static void main (String[] args) {
System.out.println (“Please enter your text: “);
Scanner in = new Scanner (System.in);
String mystr = in.nextln();
ArrayList<String> myarr = new ArrayList<String>();
for (int i=0; i<mystr.length; i++) {
String word = “”;
if(mystr[i] != “ “) {
word += mystr[i];
}
else { // seeing space
if (word != “”)
myarr.add(word);
word = “”;
}
}
if (word != “”)
myarr.add(word);
for (int =0; j<myarr.size(); j++)
System.out.println (myarr.get(i));
}
//Problem: Write a function that splits a text into single words, without using split() or StringTokenizer etc that does the same job, and without using Scanner.next(). Use indexOf() and/or substring() instead.
public static void main (String[] args) {
System.out.println (“Please enter your text: “);
Scanner in = new Scanner(System.in);
String mystr = in.nextln();
ArrayList<String> myarr = new ArrayList<String>();
while (mystr.indexOf (“ “) != -1)
if (mystr.indexOf(“ “) ! = 0)
myarr.add (mystr.substr(0, mystr.indexOf(“ “));
mystr = mystr.substr(mystr.indexOf(“ “)+1);
}
myarr.add(mystr);
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.